﻿/// <reference path="jquery-2.1.4.min.js" />
/// <reference path="createjs.js" />

var bgW = $(window).width();
bgW = 640;
var bgH = $(window).height();

var stage = new createjs.Stage("gameView");
var Container0 = new createjs.Container;
var Container1 = new createjs.Container;
var Container2 = new createjs.Container;
var imgContainer = new createjs.Container;
var imgnewContainer = new createjs.Container;
var queue = new createjs.LoadQueue();
createjs.Sound.alternateExtensions = ["mp3,wav"];
queue.installPlugin(createjs.Sound);
var LoadCanvas = function() {

	/////////////////////////启动触摸
	createjs.Touch.enable(stage);
	queue.loadManifest([
		{id:"bg",src:"bg.jpg"},
		{id:"guanghuan",src:"guanghuan.png"},
		{id:"renwu",src:"renwu.png"},
		{id:"shuohua",src:"shuohua.png"},
		{id:"touxiang",src:"touxiang.png"},
		{id:"wenzi11",src:"wenzi11.png"},
		{id:"wenzi12",src:"wenzi12.png"},
		{id:"wenzi13",src:"wenzi13.png"},
		{id:"wenzi14",src:"wenzi14.png"},
		{id:"wenzi21",src:"wenzi21.png"},
		{id:"wenzi22",src:"wenzi22.png"},
		{id:"wenzi23",src:"wenzi23.png"},
		{id:"wenzi24",src:"wenzi24.png"},
		{id:"wenzi25",src:"wenzi25.png"},
		{id:"wenzi26",src:"wenzi26.png"},
		{id:"erweima",src:"erweima.png"},
		{id:"tanchu",src:"tanchu.png"},
		{id:"zhiwen",src:"zhiwen.png"},
		{id:"shitou1",src:"shitou1.png"},
		{id:"shitou2",src:"shitou2.png"},
		{id:"shitou3",src:"shitou3.png"},
		{id:"shitou4",src:"shitou4.png"},
		{id:"shitou5",src:"shitou5.png"},
		{id:"shitou6",src:"shitou6.png"},
		{id:"shitou7",src:"shitou7.png"},
		{id:"a1",src:"a1.png"},
//		{id:"shengyin",src:"shengyin.mp3"},
//	], true, "http://jkera2016.oss-cn-shanghai.aliyuncs.com/mingxinpian/");
	], true, "image/");
	queue.on("progress", function(event) {

		if (queue.progress.toString().length > 4) {
			progress = queue.progress.toString().substr(2, 2);
		} else {
			if (queue.progress.toString().length == 3 || queue.progress.toString().length == 4) {
				progress = queue.progress * 100;
			}

			progress = queue.progress;
		}
		if (progress.toString().indexOf(".") <= 0) {
			if (progress == "00") {
				progress = "0";
			}
			//          baifenbi.text = progress + "%";
			if (progress == "1") {
				progress = "100";
				$(".loading").css("display", "none");
			}
			$(".jindutiao").html(progress + "%");
//			console.log(progress);
		}

	});
	queue.on("complete", handleComplete, this);
}
//var bg,logo1,logo2;
var handleComplete = function() {
//	alert(rukou);
	var bg = new createjs.Bitmap(queue.getResult("bg"));
	bg.scaleY = bgH/bg.getBounds().height;
	stage.addChild(bg);
	Load1();
	createjs.Ticker.setFPS(60);
	createjs.Ticker.addEventListener("tick", function(event) {
		stage.update();
	})
}
//var shengyin1 = document.getElementById("shengyin");
var Load1 = function(){
	stage.addChild(Container1);
	var renwu = new createjs.Bitmap(queue.getResult("renwu"));
	renwu.x = (bgW-renwu.getBounds().width)/2;
	renwu.y = bgH - renwu.getBounds().height;
	
	var wenzi12= new createjs.Bitmap(queue.getResult("wenzi12"));
	wenzi12.x = (bgW-wenzi12.getBounds().width)/2;
	wenzi12.y = (bgH - 795 - wenzi12.getBounds().height)/2;
	
	var wenzi11 = new createjs.Bitmap(queue.getResult("wenzi11"));
	wenzi11.x = (bgW-wenzi11.getBounds().width)/2;
	wenzi11.y = wenzi12.y - wenzi11.getBounds().height - 23;
	
	var wenzi13 = new createjs.Bitmap(queue.getResult("wenzi13"));
	wenzi13.x = (bgW-wenzi13.getBounds().width)/2;
	wenzi13.y = wenzi12.y + wenzi12.getBounds().height + 23;
	
	var shape1 = new createjs.Shape;
	var shape2 = new createjs.Shape;
	var shape3 = new createjs.Shape;
	shape1.graphics.beginFill("black").drawRect(wenzi11.x-wenzi11.getBounds().width,wenzi11.y-20,wenzi11.getBounds().width,wenzi11.getBounds().height+40);
	shape2.graphics.beginFill("black").drawRect(wenzi12.x-wenzi12.getBounds().width,wenzi12.y-20,wenzi12.getBounds().width,wenzi12.getBounds().height+40);
	shape3.graphics.beginFill("black").drawRect(wenzi13.x-wenzi13.getBounds().width,wenzi13.y-20,wenzi13.getBounds().width,wenzi13.getBounds().height+40);
	shape1.alpha = shape2.alpha = shape3.alpha = 0;
	wenzi11.mask = shape1;wenzi12.mask = shape2;wenzi13.mask = shape3;
//	var count1 = 1;
//	var goto1 = function(){
//		if(count1<15)
//		{
//			createjs.Tween.get(shape1).to({x:32*count1},0).wait(500).call(goto1);
//			count1++;
//		}
//		
//	}
//	goto1();

	var wenzi14 = new createjs.Bitmap(queue.getResult("wenzi14"));
	wenzi14.x = (bgW-wenzi14.getBounds().width)/2;
	wenzi14.y = bgH - wenzi14.getBounds().height - 40;
	
	var spriteSheetguanghuan = new createjs.SpriteSheet({
	    framerate: 1,
	    "images": [queue.getResult("guanghuan")],
	    "frames": { width: 355, height: 205, count: 38 },
	    "animations": {
	        "imgbg": [0, 38, "imgbg", 0.08],
	    }
	});
    var guanghuan = new createjs.Sprite(spriteSheetguanghuan, "imgbg");
    guanghuan.x = renwu.x + 145;guanghuan.y = renwu.y + 60;
    guanghuan.gotoAndStop();
    var kaishi = true;
    guanghuan.addEventListener("animationend",function(){
		if(kaishi)
		{
			kaishi = false;
		}
		
    })
    
    var spriteSheetshuohua = new createjs.SpriteSheet({
	    framerate: 30,
	    "images": [queue.getResult("shuohua")],
	    "frames": { width: 126, height: 72, count: 111 },
	    "animations": {
	        "imgbg": [0, 110, "imgbg", 0.13],
	        "imgbg1": [110, 110, "imgbg1", 0.2],
	    }
	});
    var shuohua = new createjs.Sprite(spriteSheetshuohua, "imgbg");
    shuohua.x = renwu.x + 255;shuohua.y = renwu.y + 440;
    shuohua.gotoAndStop();
    var kaishi = true;
    shuohua.addEventListener("animationend",function(){
		if(kaishi)
		{
			kaishi = false;
			shuohua.alpha = 0;
		}
    })
    shuohua.alpha = 0;
    
    var spriteSheetzhiwen = new createjs.SpriteSheet({
	    framerate: 30,
	    "images": [queue.getResult("zhiwen")],
	    "frames": { width: 154, height: 199, count: 203 },
	    "animations": {
	        "imgbg": [0, 40, "imgbg2", 0.2],
	        "imgbg2": [40, 102, "imgbg2", 0.2],
	    }
	});
    var zhiwen = new createjs.Sprite(spriteSheetzhiwen, "imgbg");
    zhiwen.x = (bgW-154)/2;zhiwen.y = bgH - 235;
    zhiwen.gotoAndStop();
    var kaishi = true;
    zhiwen.addEventListener("animationend",function(){
		if(kaishi)
		{
			kaishi = false;
		}
    })
    wenzi14.alpha = 0;
    
	Container1.addChild(renwu,wenzi11,wenzi12,wenzi13,shape1,shape2,shape3,wenzi14,guanghuan,shuohua,zhiwen);
	
	
	
	
    var shitou1 = new createjs.Bitmap(queue.getResult("shitou1"));
    var shitou2 = new createjs.Bitmap(queue.getResult("shitou2"));
    var shitou3 = new createjs.Bitmap(queue.getResult("shitou3"));
    var shitou4 = new createjs.Bitmap(queue.getResult("shitou4"));
    var shitou5 = new createjs.Bitmap(queue.getResult("shitou5"));
    var shitou6 = new createjs.Bitmap(queue.getResult("shitou6"));
    var shitou7 = new createjs.Bitmap(queue.getResult("shitou7"));
	shitou1.x = 170;shitou2.x = 60;shitou3.x = 60;
	shitou4.x = 480;shitou5.x = 380;shitou6.x = 535;shitou7.x = 530;
	shitou1.y = bgH-900;
	shitou2.y = shitou1.y+150;
	shitou3.y = shitou1.y+500;
	shitou4.y = shitou1.y-10;
	shitou5.y = shitou1.y+35;
	shitou6.y = shitou1.y+200;
	shitou7.y = shitou1.y+576;
	
	stage.addChild(shitou1,shitou2,shitou3,shitou4,shitou5,shitou6,shitou7);
	
	var shitouShow = function(){
		createjs.Tween.get(shitou3,{loop:true}).to({x:shitou3.x+30,y:shitou3.y-30},2000).to({x:shitou3.x+10,y:shitou3.y-10},500).to({x:shitou3.x+30,y:shitou3.y-30},500).to({x:shitou3.x-30,y:shitou3.y+10},500).to({x:shitou3.x,y:shitou3.y},2000);
		createjs.Tween.get(shitou1,{loop:true}).to({y:shitou1.y+30},5000).to({y:shitou1.y-30},5000);
		createjs.Tween.get(shitou2,{loop:true}).to({scaleX:0.7,scaleY:0.7,x:shitou2.x+50,y:shitou2.y+20},2000).to({scaleX:1,scaleY:1,x:shitou2.x-10,y:shitou2.y},2000).to({scaleX:0.7,scaleY:0.7,x:shitou2.x+50,y:shitou2.y+20},1000).to({scaleX:0.8,scaleY:0.8,x:shitou2.x+30,y:shitou2.y+20},1000).to({scaleX:1,scaleY:1,x:shitou2.x,y:shitou2.y},2000);
		createjs.Tween.get(shitou4,{loop:true}).to({y:shitou4.y+30},6000).to({y:shitou4.y-30},6000);
		createjs.Tween.get(shitou5,{loop:true}).to({y:shitou5.y+30},6000).to({y:shitou5.y-30},6000);
		createjs.Tween.get(shitou6,{loop:true}).to({x:shitou6.x-10,y:shitou6.y+30},2000).to({x:shitou6.x-30,y:shitou6.y+10,rotation:45},1000).to({x:shitou6.x,y:shitou6.y,rotation:0},2000);
		createjs.Tween.get(shitou7,{loop:true}).to({x:shitou7.x-10,y:shitou7.y+30,rotation:45},1000).to({x:shitou7.x-30,y:shitou7.y+10,rotation:45},2000).to({x:shitou7.x,y:shitou7.y,rotation:0},2000);
	}
	
	
	
	var textShow = function(){
		createjs.Tween.get(shuohua).to({alpha:1},50).call(function(){
//			createjs.Sound.play("shengyin",{loop:true});
			var shengyin = document.getElementById("shengyin");
			shengyin.play();
		})
		shuohua.play();
		createjs.Tween.get(wenzi11,{loop:true}).to({y:wenzi11.y-10},1000).to({y:wenzi11.y-0},1000).to({y:wenzi11.y+10},1000).to({y:wenzi11.y-0},1000);
		createjs.Tween.get(wenzi12,{loop:true}).to({y:wenzi12.y-10},1000).to({y:wenzi12.y-0},1000).to({y:wenzi12.y+10},1000).to({y:wenzi12.y-0},1000);
		createjs.Tween.get(wenzi13,{loop:true}).to({y:wenzi13.y-10},1000).to({y:wenzi13.y-0},1000).to({y:wenzi13.y+10},1000).to({y:wenzi13.y-0},1000);
		createjs.Tween.get(shape1).to({x:wenzi11.getBounds().width},6000).call(function(){

			createjs.Tween.get(shape2).to({x:wenzi12.getBounds().width},5000).wait(500).call(function(){

				createjs.Tween.get(shape3).to({x:wenzi13.getBounds().width},2000).call(function(){
					zhiwen.gotoAndPlay("imgbg");
					zhiwen.addEventListener("mousedown",function(){
						zhiwen.alpha = 0;
						Load2();
					})
				});
			});
		});
	}
	
	guanghuan.alpha = shitou1.alpha = shitou2.alpha = shitou3.alpha = shitou4.alpha = shitou5.alpha = shitou6.alpha = shitou7.alpha = 0;
	createjs.Tween.get(renwu).to({alpha:0}).wait(3000).to({alpha:1},3000).wait(2000).call(function(){
		createjs.Tween.get(shitou1).to({alpha:1},1000);
		createjs.Tween.get(shitou2).to({alpha:1},1000);
		createjs.Tween.get(shitou3).to({alpha:1},1000);
		createjs.Tween.get(shitou4).to({alpha:1},1000);
		createjs.Tween.get(shitou5).to({alpha:1},1000);
		createjs.Tween.get(shitou6).to({alpha:1},1000);
		createjs.Tween.get(shitou7).to({alpha:1},1000);
		guanghuan.gotoAndPlay("imgbg");
		createjs.Tween.get(guanghuan).to({alpha:1},1000);
		textShow();
//		shitouShow();
	})
}
var Load2 = function(){
//	createjs.Sound.stop("shengyin");
	var shengyin = document.getElementById("shengyin");
	shengyin.pause();
	stage.removeChild(Container1);
	
//	createjs.Tween.get(Container1).to({alpha:0},1000).call(function(){
//
//	});
	stage.addChild(Container2);
	var wenzi21 = new createjs.Bitmap(queue.getResult("wenzi21"));
	wenzi21.x = 40;
	wenzi21.y = 20;
	
	var wenzi24 = new createjs.Bitmap(queue.getResult("wenzi24"));
	wenzi24.x = (bgW-wenzi24.getBounds().width)/2;
	wenzi24.y = (bgH-wenzi24.getBounds().height)/2+50;
	
	var wenzi23 = new createjs.Bitmap(queue.getResult("wenzi23"));
	wenzi23.x = wenzi24.x +188;wenzi23.y = wenzi24.y -60;
	
	var touxiang = new createjs.Bitmap(document.getElementById("touxiang"));
	touxiang.x = wenzi23.x + 18;touxiang.y = wenzi23.y + 18;
	touxiang.scaleX = 140/$("#touxiang").css("width").split("px")[0];
	touxiang.scaleY = 140/$("#touxiang").css("height").split("px")[0];
	$("#touxiang").css({left:touxiang.x,top:touxiang.y})
	
	var shapeTX = new createjs.Shape;
	shapeTX.graphics.beginFill("black").drawCircle(touxiang.x+70,touxiang.y+70,70);
	shapeTX.alpha = 0;
	touxiang.mask = shapeTX;
	var wenzi22 = new createjs.Bitmap(queue.getResult("wenzi22"));
	wenzi22.x = (bgW-wenzi22.getBounds().width)/2;
	wenzi22.y = (wenzi24.y - wenzi22.getBounds().height - wenzi21.getBounds().height-wenzi21.y)/2+wenzi21.y+wenzi21.getBounds().height;
	
	var xingming = new createjs.Text(username, "40px Arial", "#797979");
	xingming.x = wenzi22.x+320;
	xingming.y = wenzi22.y+100;
	xingming.textBaseline = "alphabetic";
	
	var wenzi25 = new createjs.Bitmap(queue.getResult("wenzi25"));
	wenzi25.x = 45;wenzi25.y = (bgH-wenzi24.y-wenzi24.getBounds().height-wenzi25.getBounds().height)/2+wenzi24.y+wenzi24.getBounds().height;
	var wenzi26 = new createjs.Bitmap(queue.getResult("wenzi26"));
	wenzi26.x = 340;wenzi26.y = wenzi25.y;
	var erweima = new createjs.Bitmap(queue.getResult("erweima"));
	erweima.x = (bgW-erweima.getBounds().width)/2;
	erweima.y = (bgH-wenzi24.y-wenzi24.getBounds().height-erweima.getBounds().height)/2+wenzi24.y+wenzi24.getBounds().height;
	erweima.alpha = 0;
	
	var tanchu = new createjs.Bitmap(queue.getResult("tanchu"));
	tanchu.x = (bgW-tanchu.getBounds().width)/2;
	tanchu.y = (bgH-tanchu.getBounds().height)/2;
	
	var shapetc = new createjs.Shape;
	shapetc.graphics.beginFill("black").drawRect(tanchu.x+110,tanchu.y+190,255,68);
	
	var shape = new createjs.Shape;
	shape.graphics.beginFill("black").drawRect(0,0,bgW,bgH);
	tanchu.alpha = shapetc.alpha = shape.alpha = 0;

//	var a1 = new createjs.Bitmap(queue.getResult("a1"));
	var a1 = new createjs.Bitmap(document.getElementById("wenan"));
	a1.x = (bgW-a1.getBounds().width)/2;
	a1.y = wenzi24.y + 140;
	wenzi25.addEventListener("mousedown",function(){
		shape.alpha = 0.8;
		shapetc.alpha = 0.01;
		tanchu.alpha = 1;
	})
	shapetc.addEventListener("mousedown",function(){
		try{
			shape.alpha = shapetc.alpha = tanchu.alpha = 0;
			wenzi25.alpha = wenzi26.alpha = 0;erweima.alpha = 1;
			var image = document.getElementById("lastimg");
			setTimeout(function() {
				try{
					var imgsrc = document.getElementById("gameView").toDataURL("image/jpg");
					image.src = imgsrc;
					$("#lastimg").css("display","block");
//					$("#gameView").css("display","none");
					
				}catch(e){
					//TODO handle the exception
					alert(e.message);
				}
				
				
			}, 1000)
		}catch(e){
			//TODO handle the exception
			alert(e.message);
		}
		
	})
	wenzi26.addEventListener("mousedown",function(){
		location.href = encodeURI("http://www.baidu.com");
	})
	
	
	
	Container2.addChild(wenzi21,wenzi24,a1,touxiang,wenzi23,wenzi22,xingming,wenzi25,wenzi26,erweima,shapeTX,tanchu,shape,shapetc,tanchu);
	
}

var getlength = function(str)
{  
    var realLength = 0;  
    for (var i = 0; i < str.length; i++)   
    {  
        charCode = str.charCodeAt(i);  
        if (charCode >= 0 && charCode <= 128)   
        realLength += 1;  
        else   
        realLength += 2;  
    }  
    return realLength;  
}  




















































































